package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.CompanyBaseDAO;
import com.yang.doctorrecruitment.dto.CompanyBase;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class GetCompanyBaseAction extends ActionSupport {
    private String UserID;
    private JSON json;

    public String GetCompanyBase(){
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");
        CompanyBase companyBase= CompanyBaseDAO.selectCompany(UserID);
        JSONObject js=new JSONObject();
        js.put("CompanyName",companyBase.getCompanyName());
        js.put("CompanyCorporation",companyBase.getCompanyCorporation());
        js.put("CompanyAddress",companyBase.getCompanyAddress());
        js.put("CompanyEmail",companyBase.getCompanyEmail());
        js.put("CompanyIntroduce",companyBase.getCompanyIntroduce());
        js.put("CompanyNature",companyBase.getCompanyNature());
        js.put("CompanyScale",companyBase.getCompanyScale());
        js.put("CompanyTelphone",companyBase.getCompanyTelphone());
        js.put("CompanyType",companyBase.getCompanyType());

        js.put("Companylicense",companyBase.getCompanylicense());

        js.put("CompanyIdentified",companyBase.getCompanyIdentified());
        js.put("FilePath",companyBase.getFilePath());

        json=js;

        return SUCCESS;
    }

    public String GetCompanyBaseByUser(){
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        String UserID= request.getParameter("UserID");
        CompanyBase companyBase= CompanyBaseDAO.selectCompany(UserID);
        JSONObject js=new JSONObject();
        js.put("CompanyName",companyBase.getCompanyName());
        js.put("CompanyCorporation",companyBase.getCompanyCorporation());
        js.put("CompanyAddress",companyBase.getCompanyAddress());
        js.put("CompanyEmail",companyBase.getCompanyEmail());
        js.put("CompanyIntroduce",companyBase.getCompanyIntroduce());
        js.put("CompanyNature",companyBase.getCompanyNature());
        js.put("CompanyScale",companyBase.getCompanyScale());
        js.put("CompanyTelphone",companyBase.getCompanyTelphone());
        js.put("CompanyType",companyBase.getCompanyType());

        js.put("Companylicense",companyBase.getCompanylicense());

        js.put("CompanyIdentified",companyBase.getCompanyIdentified());
        js.put("FilePath",companyBase.getFilePath());

        json=js;

        return SUCCESS;
    }


    public JSON getJson() {
        return json;
    }

    public void setJson(JSON json) {
        this.json = json;
    }

    public String getUserID() {
        return UserID;
    }

    public void setUserID(String userID) {
        UserID = userID;
    }
}
